package com.mage.servlet;

import com.mage.bean.PageBean;
import com.mage.dao.UserDao;
import com.mage.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/SearchDengjiServlet")
public class SearchDengjiServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public SearchDengjiServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            //1. 获取需要显示的页码数
            int currentPage = 1;
            if(request.getParameter("currentPage")!=null) {
                currentPage =Integer.parseInt( request.getParameter("currentPage"));
            }
            UserDao service = new UserDaoImpl();
            //2. 根据指定的页数，去获取该页的数据回来
            if (request.getParameter("dengji") != null){
                String dengji = request.getParameter("dengji");
                PageBean pageBean= service.findUserByPagesAndDengji(currentPage,dengji);
                request.setAttribute("pageBean", pageBean);
                //3. 跳转界面。
                request.getRequestDispatcher("/Super/User_selectAll.jsp").forward(request, response);
            }else{
                request.getRequestDispatcher("UserListServlet").forward(request, response);
            }

        }catch (Exception e) {
            // TODO: handle exception
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
